﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace KillMasterLu
{
    public partial class Form1 : Form
    {
        private Point p;
        private SysInfoMonitor monitor;
        public Form1()
        {
            InitializeComponent();
            monitor = new SysInfoMonitor();
        }

        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (this.Visible)
            {
                this.Hide();
            }
            else
            {
                this.Show();
            }

            //if (this.WindowState == System.Windows.Forms.FormWindowState.Minimized)
            //    this.WindowState = System.Windows.Forms.FormWindowState.Normal;
        }
        private void timer1_Tick(object sender, EventArgs E)
        {
            if (Cursor.Position != p)
            {
                this.Hide();
                timer1.Stop();
            }
        }
        private void notifyIcon1_MouseMove(object sender, MouseEventArgs e)
        {
            p = Cursor.Position;
            if (!timer1.Enabled)
            {
                timer1.Start();
                this.Show();
            }
            Rectangle rectangle = Screen.AllScreens[0].WorkingArea;
            this.StartPosition = FormStartPosition.Manual;
            int x = (int)Math.Round((double)p.X / 30) * 30;
            this.Location = new Point(x - this.Width / 2, rectangle.Height - this.Height - 5);
            this.TopMost = true;

            String cputem = monitor.GetTher();

            cpulabel.Text = cputem;
            
            

            //System.Threading.Thread thread = new System.Threading.Thread(() =>
            //{
            //    while (this.Top >= rectangle.Height - this.Height)
            //    {
            //        this.Invoke(new MethodInvoker(delegate
            //        {
            //            this.Top = this.Top - 1;
            //            System.Threading.Thread.Sleep(100);
            //            Application.DoEvents();
            //        }));
            //    }
            //});
            //thread.Start();
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void 打开界面ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.Visible)
            {
                this.Hide();
            }
            else
            {
                this.Show();
            }
        }
        private void Form1_SizeChanged(object sender, EventArgs e)
        {
            if (WindowState == FormWindowState.Minimized)
            {
                this.Hide();
                this.notifyIcon1.Visible = true;
                this.notifyIcon1.ShowBalloonTip(30, "注意", "大家好，这是一个事例", ToolTipIcon.Info);
            }
        }

        private void 闪动ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.notifyIcon1.ShowBalloonTip(30, "注意", "大家好，这是一个事例", ToolTipIcon.Info);

            //while (true)
            //{

            //    this.notifyIcon1.Icon = new Icon("ico/bw.ico");

            //    //Thread.Sleep(100);

            //    this.notifyIcon1.Icon = new Icon("ico/c.ico");

            //    //Thread.Sleep(100);

            //}
        }


        // 放置图标到任务栏中，并隐藏自己

        //void CTaskbarIconDlg::PutIconToTaskbar()

        //{

        //NOTIFYICONDATA  nid;

        //memset( &nid, 0, sizeof(nid) );

        //nid.cbSize = sizeof(nid);

        //nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;

        //strcpy( nid.szTip, "我的任务栏图标" );

        //nid.hWnd = m_hWnd;

        //nid.uCallbackMessage = UM_NOTIFY;

        //nid.hIcon = LoadIcon( AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDI_TASKBAR) );

        //if ( nid.hIcon == NULL )

        //{

        //TRACE( TEXT("loadicon failed, return %d/n"), GetLastError() );

        //}

        //else

        //{

        //if ( Shell_NotifyIcon( NIM_ADD, &nid ) )

        //{

        // 添加成功，就隐藏自己

        //MoveWindow( -10, 0, 1, 1 );

        //ModifyStyleEx(WS_EX_APPWINDOW,WS_EX_TOOLWINDOW);//隐藏任务栏图标

        //}

        //}

        //}
        //    }





    }
}
